home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / Polyhash.sig < prev    next >
Encoding:
Text File  |  1996-07-03  |  4.0 KB  |  93 lines  |  [TEXT/R*ch]

  1. (* Polyhash -- polymorphic hashtables as in the SML/NJ Library, 1995-01-10 *)
  2.  
  3. type ('key, 'data) hash_table
  4.  
  5. val mkTable   : ('_key -> int) * ('_key * '_key -> bool) -> int * exn 
  6.                 -> ('_key, '_data) hash_table
  7. val numItems  : ('key, 'data) hash_table -> int
  8. val insert    : ('_key, '_data) hash_table -> '_key * '_data -> unit
  9. val find      : ('key, 'data) hash_table -> 'key -> 'data
  10. val peek      : ('key, 'data) hash_table -> 'key -> 'data option
  11. val remove    : ('key, 'data) hash_table -> 'key -> 'data
  12. val listItems : ('key, 'data) hash_table -> ('key * 'data) list
  13. val apply     : ('key * 'data -> unit) -> ('key, 'data) hash_table -> unit
  14. val map       : ('_key * 'data -> '_res) -> ('_key, 'data) hash_table 
  15.                 -> ('_key, '_res) hash_table
  16. val filter    : ('key * 'data -> bool) -> ('key, 'data) hash_table -> unit
  17. val transform : ('data -> '_res) -> ('_key, 'data) hash_table 
  18.                 -> ('_key, '_res) hash_table
  19. val copy      : ('_key, '_data) hash_table -> ('_key, '_data) hash_table
  20. val bucketSizes : ('key, 'data) hash_table -> int list
  21.  
  22. (*** Polymorphic hash primitives from Caml Light *)
  23.  
  24. val hash        : 'key -> int
  25. val hash_param  : int -> int -> 'key -> int
  26. val mkPolyTable : int * exn -> (''_key, '_data) hash_table
  27.  
  28.  
  29. (* [('key, 'data) hash_table] is the type of hashtables with keys of type
  30.    'key and data values of type 'data.
  31.  
  32.    [mkTable (hashVal, sameKey) (sz, exc)] returns a new hashtable,
  33.    using hash function hashVal and equality predicate sameKey.  The sz
  34.    is a size hint, and exc is the exception raised by function find.
  35.    It must be the case that sameKey(k1, k2) implies hashVal(k1) =
  36.    hashVal(k2) for all k1,k2.
  37.  
  38.    [numItems htbl] is the number of items in the hash table.
  39.  
  40.    [insert htbl (k, d)] inserts data d for key k.  If k already had an
  41.    item associated with it, then the old item is overwritten.
  42.  
  43.    [find htbl k] returns d, where d is the data item associated with key k, 
  44.    or raises the exception (given at creation of htbl) if there is no such d.
  45.  
  46.    [peek htbl k] returns SOME d, where d is the data item associated with 
  47.    key k, or NONE if there is no such d.
  48.  
  49.    [remove htbl k] returns d, where d is the data item associated with key k, 
  50.    removing d from the table; or raises the exception if there is no such d.
  51.  
  52.    [listItems htbl] returns a list of the (key, data) pairs in the hashtable.
  53.  
  54.    [apply f htbl] applies function f to all (key, data) pairs in the 
  55.    hashtable, in some order.
  56.  
  57.    [map f htbl] returns a new hashtable, whose data items have been
  58.    obtained by applying f to the (key, data) pairs in htbl.  The new
  59.    tables have the same keys, hash function, equality predicate, and
  60.    exception, as htbl.
  61.  
  62.    [filter p htbl] deletes from htbl all data items which do not
  63.    satisfy predicate p.
  64.  
  65.    [transform f htbl] as map, but only the (old) data values are used
  66.    when computing the new data values.
  67.  
  68.    [copy htbl] returns a complete copy of htbl.
  69.  
  70.    [bucketSizes htbl] returns a list of the sizes of the buckets.
  71.    This is to allow users to gauge the quality of their hashing
  72.    function.  
  73.  
  74.    [hash k] returns apositive integer to key k. It holds that if k1=k2
  75.    implies hash(k1) = hash(k2), so this function can be used when
  76.    creating hashtables.  Moreover, hash(k) always terminates, even on
  77.    cyclic structures.  (From the Caml Light implementation).
  78.  
  79.    [hash_param n m x] computes a hash value for k with the same
  80.    properties as for hash. The parameters n and m give more precise
  81.    control over hashing.  Hashing performs a depth-first,
  82.    right-to-left traversal of the structure x, stopping after n
  83.    meaningful nodes were encountered, or m nodes, meaningful or not,
  84.    were encountered. Meaningful nodes are: integers; floating-point
  85.    numbers; strings; characters; booleans; references; and constant
  86.    constructors. 
  87.  
  88.    [mkPolyTable (sz, exc)] creates a new hashtable using the
  89.    polymorphic hash function and ML equality (hash, op =).  The int is a
  90.    size hint and the exception exc is to be raised by find.  
  91. *)
  92.  
  93.